package com.lmc.gobang.mapper;

import com.lmc.gobang.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    //注册
    @Insert("insert into user values(null,#{username},#{password},1000,0,0,0,now(),now() )")
     Boolean registerUser(User user);

    //根据用户名获取用户信息用于登录功能
    @Select("select * from user where username = #{userName} and delete_flag = 0")
    User getUserByUsername(String username);

    //更新获胜方信息，总场数+1，获胜场数+1，积分+30
    @Update("update user set total_count = total_count + 1 , win_count = win_count + 1, " +
            "score = score + 30 where user_id = #{userId}")
    void userWin(int userId);

    //更新失败方信息，总场数+1,积分-30
    @Update("update user set total_count = total_count + 1, " +
            "score = score - 30 where user_id = #{userId}")
    void userLose(int userId);
}











































